package com.likeycy.my.sort.cmp;

/**
 * @ClassName: InsertionSort1
 * @Description: 插入排序第一版
 * @Author: sodagreen
 * @Date: 2021/3/29 17:12
 * @Version: 1.0
 */
public class InsertionSort1<T extends Comparable<T>> extends Sort<T> {

    @Override
    protected void sort() {
        for (int begin = 1; begin < array.length; begin++) {
            int curIndex = begin;
            while (curIndex > 0 && cmp(curIndex, curIndex - 1) < 0) {
                swap(curIndex, curIndex -1);
                curIndex--;
            }
        }
    }
}
